package com.dlwx.parttimetalent.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.base.BaseActivity;
import com.dlwx.parttimetalent.bean.IncomeDetailBean;
import com.dlwx.parttimetalent.comm.Constant;
import com.dlwx.parttimetalent.comm.Http;
import com.dlwx.parttimetalent.utils.DealResult;
import com.dlwx.parttimetalent.utils.OkgoUtil;
import com.dlwx.parttimetalent.utils.ToastUtils;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class IncomeDetailActivity extends BaseActivity {

    @BindView(R.id.title_left_one_btn)
    ImageView titleLeftOneBtn;
    @BindView(R.id.tv_middle_title)
    TextView tvMiddleTitle;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.tv_classify)
    TextView tvClassify;
    @BindView(R.id.tv_type)
    TextView tvType;
    private String capitalid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_income_detail);
        ButterKnife.bind(this);
        initView();
        getDatas();
    }

    private void initView() {
        titleLeftOneBtn.setVisibility(View.VISIBLE);
        tvMiddleTitle.setVisibility(View.VISIBLE);
        tvMiddleTitle.setText("收支记录明细");
        capitalid = getIntent().getStringExtra("id");
    }

    @OnClick({R.id.title_left_one_btn, R.id.tv_middle_title})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_left_one_btn:
                this.finish();
                break;
            case R.id.tv_middle_title:
                break;
        }
    }

    public void getDatas() {
        loadingDialog.show();
        OkgoUtil.post(Http.CapitalDetails, IncomeDetailActivity.this)
                .params("capitalid", capitalid)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        loadingDialog.dismiss();
                        IncomeDetailBean parentBean = DealResult.getInstance().dealDatas(IncomeDetailActivity.this
                                , response, new TypeToken<IncomeDetailBean>() {
                                }.getType());
                        if (parentBean == null) {
                            return;
                        }
                        int code = parentBean.getCode();
                        if (code == Constant.SUCESS || code == Constant.EMPTY) {
                            setDatas(parentBean.getBody());
                        } else {
                            ToastUtils.toastForShort(IncomeDetailActivity.this, parentBean.getResult());

                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        loadingDialog.dismiss();
                        super.onError(response);
                        ToastUtils.toastForShort(IncomeDetailActivity.this, getString(R.string.bad_net));
                    }
                });
    }

    private void setDatas(IncomeDetailBean.BodyBean body) {
        tvTitle.setText(body.getCdesc());
        tvPrice.setText(body.getPrice());
        tvStatus.setText(body.getTradestatus());
        tvNum.setText("订单号:"+body.getOrderno());
        tvType.setText("付款方式："+body.getPaytype());
        tvClassify.setText("账单分类："+body.getCapType());
    }
}
